import React from 'react';
import {Modal,Form,Input } from 'antd';
import {connect} from 'dva';
const  FormItem=Form.Item;
const formItemLayout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 8 },
};


class AddAdminModalUI extends React.Component {

  handleOk = () => {
      this.props.form.validateFieldsAndScroll((errors, values) => {
        if (errors) {

        } else {
          this.props.dispatch({
            type: 'admin/add',
            payload:values
          });
          this.props.form.resetFields();
          this.props.showOrHiddenModalVisible(false);
        }
      });
  };

  handleCancel = () => {
    this.props.form.resetFields();
    this.props.showOrHiddenModalVisible(false);
  };

  render() {
    return(
      <Modal title="添加用户" visible={true} onOk={()=>{this.handleOk()}}
             onCancel={()=>{this.handleCancel()}} okText="确认" cancelText="取消" maskClosable={false}
      >
        <Form>
          <FormItem {...formItemLayout}  label="用户名" >
            {
              this.props.form.getFieldDecorator('userName', {
                rules: [
                  {
                    required: true,
                  },
                ],
              })(<Input  placeholder="用户名" size="large"/>)
            }
          </FormItem>
          <FormItem {...formItemLayout}  label="手机" >
            {
              this.props.form.getFieldDecorator('cellphone', {rules: [{required: true, message:"请输入手机号",
                type: "string",
                pattern: "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$" },],
              })(<Input  placeholder="用户名" size="large"/>)
            }
          </FormItem>
          <FormItem {...formItemLayout}  label="密码" >
            {
              this.props.form.getFieldDecorator('pswd', {rules: [{required: true, },],
              })(<Input type="password" placeholder="密码" size="large"/>)
            }
          </FormItem>
          <FormItem {...formItemLayout}  label="姓名" >
            {
              this.props.form.getFieldDecorator('name', {rules: [],
              })(<Input  placeholder="姓名" size="large"/>)
            }
          </FormItem>
        </Form>

      </Modal>

    );
  }
}

export default connect()(Form.create()(AddAdminModalUI));
